home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / picture ƒ / line.c < prev    next >
Text File  |  1990-11-08  |  2KB  |  114 lines

  1. /*
  2. *    FILE:        line.c
  3. *    AUTHOR:        R. Gonzalez
  4. *    CREATED:    October 6, 1990
  5. *
  6. *    defines methods for 3D line segment
  7. */
  8.  
  9. # include    "line.h"
  10.  
  11. /******************************************************************
  12. *    initialize
  13. ******************************************************************/
  14. boolean    Line::init(void)
  15. {
  16.     c1 = new(Coord3);
  17.     c1->init();
  18.     c2 = new(Coord3);
  19.     c2->init();
  20.     set_coord(10.,0.,0.,10.,0.,1.);
  21.     set_color(WHITE);
  22.     
  23.     return TRUE;
  24. }
  25.  
  26. /******************************************************************
  27. *    set coordinates
  28. ******************************************************************/
  29. void    Line::set_coord(double x1,double y1,double z1,
  30.                 double x2,double y2,double z2)
  31. {
  32.     c1->x = x1;
  33.     c1->y = y1;
  34.     c1->z = z1;
  35.     c2->x = x2;
  36.     c2->y = y2;
  37.     c2->z = z2;
  38. }
  39.     
  40. /******************************************************************
  41. *    set color
  42. ******************************************************************/
  43. void    Line::set_color(color line_color_val)
  44. {
  45.     line_color = line_color_val;
  46. }
  47.     
  48. /******************************************************************
  49. *    draw 3D line
  50. ******************************************************************/
  51. void    Line::draw(Camera* camera,Projector* projector,
  52.                     Transformation* trans)
  53. {
  54.     boolean        success = TRUE;
  55.     Coord2        *image1,
  56.                 *image2;
  57.     Coord3        *new_coord;
  58.     
  59.     image1 = new(Coord2);
  60.     image1->init();
  61.     image2 = new(Coord2);
  62.     image2->init();
  63.     new_coord = new(Coord3);
  64.     new_coord->init();
  65.     
  66.     new_coord->apply(c1,trans);
  67.     if (!camera->take_photo(image1,new_coord))
  68.         success = FALSE;
  69.     new_coord->apply(c2,trans);
  70.     if (!camera->take_photo(image2,new_coord))
  71.         success = FALSE;
  72.     if (success)
  73.         projector->show_line(image1,image2,line_color);
  74.     
  75.     image1->destroy();
  76.     delete(image1);
  77.     image2->destroy();
  78.     delete(image2);
  79.     new_coord->destroy();
  80.     delete(new_coord);
  81. }
  82.  
  83. /******************************************************************
  84. *    move line coordinates
  85. ******************************************************************/
  86. void    Line::move(Transformation* trans)
  87. {
  88.     Coord3    *temp;
  89.     
  90.     temp = new(Coord3);
  91.     temp->init();
  92.     temp->equate(c1);
  93.     c1->apply(temp,trans);
  94.     temp->equate(c2);
  95.     c2->apply(temp,trans);
  96.     temp->destroy();
  97.     delete(temp);
  98. }
  99.  
  100. /******************************************************************
  101. *    destroy
  102. ******************************************************************/
  103. boolean    Line::destroy(void)
  104. {
  105.     c1->destroy();
  106.     delete(c1);
  107.     c2->destroy();
  108.     delete(c2);
  109.     
  110.     return TRUE;
  111. }
  112.  
  113.  
  114.